from django.db import models
from datetime import datetime

class User(models.Model):
    userId = models.AutoField(primary_key=True)
    username = models.CharField(max_length=32)
    password = models.CharField(max_length=32)
    user_sex = models.CharField(max_length=6)
    email = models.CharField(max_length=64,null = True)
    phone = models.CharField(max_length=11)
    firstname = models.CharField(max_length=6,null = True)
    lastname = models.CharField(max_length=12,null = True)
    avatar = models.CharField(max_length=255)#头像
    is_superuser = models.IntegerField(default=0) #0表示普通用户  1 表示超级管理员
    last_login = models.DateField(null = True)
    user_register_time = models.DateField(default=datetime.now())
    class Meta:
        db_table = 't_user'


class Blog(models.Model):
    blog_id = models.AutoField(primary_key=True)
    blog_title = models.CharField(max_length=100)
    blog_content = models.TextField()
    user = models.ForeignKey('User')
    type = models.ForeignKey('BlogType')
    blog_status = models.IntegerField(default= 0) # 0 为草稿 1 表示发布
    create_time = models.DateField(default=datetime.now())
    update_time = models.DateField(null = True)
    cover_image = models.CharField(max_length= 256,null = True)
    class Meta:
        db_table = 't_blog'

class Comment(models.Model):
    comment_id = models.AutoField(primary_key=True)
    comment_content = models.CharField(max_length=500)
    blog = models.ForeignKey('Blog')
    createtime = models.DateTimeField(default=datetime.now())
    user = models.ForeignKey('User')
    replyid = models.IntegerField(null= True)
    class Meta:
        db_table = 't_comment'
class BlogTag(models.Model):
    tag_id = models.AutoField(primary_key=True)
    blog = models.ForeignKey("Blog")
    class Meta:
        db_table = 't_tag_blog'
class BlogType(models.Model):
    type_id = models.AutoField(primary_key=True)
    type_name = models.CharField(max_length=32)
    class Meta:
        db_table = 'blog_type'
